<template>
  <div class="display header">
    <el-card class="box-card card_list">
      <template #header>
        <div class="customerTitle1">
          <div>
            <span class="leve_title" >{{route.query.path != 1?'样品订单':'样品订单详情'}}</span>
            <span class="add_order_font1">
           <span>
             <span>
               总单号：
             </span>
             <span>
              {{groupList && groupList.uid}}
             </span>
           </span>
            <span>
             <span class="add_order_font2">
               订单状态：
             </span>
             <span >
               {{groupList && groupList.status_str}}
             </span>
           </span>
               <span class="add_order_font2">销售员：{{groupList && groupList.sales_dept_name || ''}}部门- {{ groupList && groupList.update_user_name || ''}} </span>
           </span>
          </div>
          <div>
<!--            <el-button size="small" @click="back">{{route.query.path != 1?'取消':'返回'}}</el-button>-->
            <el-button @click="back">{{'返回'}}</el-button>
            <el-button
              v-if="route.query.path != 1"
              class="customerButton1"
              plain
              type="primary"
              @click="share_save(form_new_date,0)"
            >
              暂存
            </el-button>
            <el-button
              v-if="route.query.path != 1"
              class="customerButton1"
              plain
              type="primary"
              @click="share_save(form_new_date,1)"
            >
              保存
            </el-button>
            <el-button  v-if="route.query.path != 1" type="primary" @click="share_save(form_new_date,2)">
              提交
            </el-button>
          </div>
        </div>
      </template>
    </el-card>
    <el-card>
      <div class="new_font1 titleHead1" >
<!--        <div class="titleDiv"/>-->
      基本信息
        <span class="title1">{{ }}</span>
    </div>
      <div :class="route.query.path == 1 && 'displayForm'">
        <el-form
          label-width="105px"
          ref="form_new_date"
          :model="form_new_list"
          :rules=" route.query.path == 1 ? []: rules"
          :disabled ="route.query.path == 1"
        >
          <el-row :gutter="24">
<!--            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="订单号" prop="uid" class="form_node">
                <el-input  v-model="form_new_list.uid" disabled />
              </el-form-item>
            </el-col>-->
            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="客户" prop="customer_uid">
                <VabSelectForm :clearable="false" v-if="customer_list.length >0"  v-model="form_new_list.customer_uid" :options="customer_list"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="销售组织" prop="sales_org_id">
                <VabSelectForm @change="updateValue" :clearable="false" v-if="sales_org_list.length >0"  v-model="form_new_list.sales_org_id" :options="sales_org_list"/>
              </el-form-item>
            </el-col>
<!--            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="价目表" prop="price_list_uid" class="form_node">
                <VabSelectForm disabled :clearable="false" v-if="price_list.length >0"  v-model="form_new_list.price_list_uid" :options="price_list"/>
              </el-form-item>
            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="折扣表" prop="discount_uid" class="form_node">
                <VabSelectForm disabled  :clearable="false" v-if="discount_list.length >0"  v-model="form_new_list.discount_uid" :options="discount_list"/>
              </el-form-item>
            </el-col>-->
            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
            <el-form-item label="期望运输方式" prop="transport_type">
              <el-select
                filterable
                v-model="form_new_list.transport_type"
                class="width_100"
                placeholder="请选择"
              >
                <el-option v-for="item in transport_type_list" :key="item.value"  :disabled="item.display" :label="item.label" :value="item.value">
                  <span style="float: left;font-weight: 600;width: 100%;color: rgb(105, 107, 111); cursor: pointer;" v-if="item.label == '自定义'"  @click="transport">{{ item.label }}</span>
                  <span style="float: left" v-if="item.label != '自定义'" >{{ item.label }}</span>
                </el-option>
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="运费付款方式" prop="payment_type">
                <VabSelectForm  :clearable="false" v-if="payment_type_list.length >0"  v-model="form_new_list.payment_type" :options="payment_type_list"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="16" :xl="16">
              <el-form-item  label="备注" prop="remark">
                <el-input
                  v-if="route.query.path != 1"
                  v-model.trim="form_new_list.remark"
                  autosize
                  type="textarea"
                />
                <span v-if="route.query.path == 1">
                  {{form_new_list.remark}}
                </span>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="销售员" prop="sales_user_id">
                <VabSelectForm  :clearable="false" v-if="sales_user_list.length >0"  v-model="form_new_list.sales_user_id" :options="sales_user_list"/>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="销售部门" prop="sales_dept_id">
                <VabSelectForm  :clearable="false" v-if="sales_dept_list.length >0"  v-model="form_new_list.sales_dept_id" :options="sales_dept_list"/>
              </el-form-item>
            </el-col>
<!--            <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="8">
              <el-form-item label="销售组" prop="sales_group_id">
                <VabSelectForm  :clearable="false" v-if="sales_group_list.length >0"  v-model="form_new_list.sales_group_id" :options="sales_group_list"/>
              </el-form-item>
            </el-col>-->
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card id="financeIds">
      <ProductsInQuick ref="products_ref"  v-model:copyProductNumber="copyProductNumber" />
    </el-card>
    <el-card id="financeId">
      <div class="customerTitle1 new_font1">
        <span class="titleHead1">地址信息</span>
        <el-button v-if=" route.query.path != 1" type="primary" @click="openAddress">
          地址簿
        </el-button>
      </div>
      <div v-if=" route.query.path != 1">
        <el-table
          border
          :data="addressList"
          height="450px"
        >
          <el-table-column label="序号" align="center" width="80">
            <template #default="props">
              <div class="table_style">
                <span style="margin-left: 5px"
                      v-text="(props.$index + 1)"
                ></span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="shipping_contact" align="center" width="150">
            <template #header>
                <span class="spanFont">
                  *
                </span>
              <span>
                  联系人
                </span>
            </template>
            <template #default="props">
              <el-input v-model.trim="props.row.shipping_contact" />
            </template>
          </el-table-column>
          <el-table-column prop="shipping_tel" align="center" width="150">
            <template #header>
                <span class="spanFont">
                  *
                </span>
              <span>
                  联系电话
                </span>
            </template>
            <template #default="props">
              <el-input v-model.trim="props.row.shipping_tel" />
            </template>
          </el-table-column>
          <el-table-column prop="province" align="center" min-width="200">
            <template #header>
                <span class="spanFont">
                  *
                </span>
              <span>
                  省/市/区
                </span>
            </template>
            <template #default="props">
              <el-cascader
                placeholder=" "
                ref="address_ref"
                v-model="props.row.shipping_address"
                :options="areaOption"
                style="width:100%;display: inline-block"
                :props="{ value: 'name', label: 'name' }"
              >
                <template #default="{ data }">
                  <span>{{ data.name }}</span>
                </template>
              </el-cascader>
            </template>
          </el-table-column>
          <el-table-column prop="address" align="center" min-width="200">
            <template #header>
                <span class="spanFont">
                  *
                </span>
              <span>
                 详细地址
                </span>
            </template>
            <template #default="props">
              <el-input v-model.trim="props.row.address" />
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="70">
            <template #default="props">
              <vab-icon
                icon="add-circle-line"
                class="icon_color"
                @click="handleClickAdd(props.row)"
              />
              <vab-icon
                v-if="addressList.length>1"
                icon="delete-bin-5-line"
                @click="handleClickRemove(props.row)"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div v-if="route.query.path == 1" >
        <el-table
          border
          :data="addressList"
          height="450px"
        >
          <el-table-column label="序号" align="center" width="80">
            <template #default="props">
              <div class="table_style">
                <span style="margin-left: 5px"
                      v-text="(props.$index + 1)"
                ></span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="shipping_contact" align="center" width="150">
            <template #header>
              <span>
                  联系人
                </span>
            </template>
            <template #default="props">
               <span
                 class="ellipsis">
                  {{props.row.shipping_contact || '--'}}
               </span>

            </template>
          </el-table-column>
          <el-table-column prop="shipping_tel" align="center" width="150">
            <template #header>
              <span>
                  联系电话
                </span>
            </template>
            <template #default="props">
                <span
                  class="ellipsis">
                  {{props.row.shipping_tel || '--'}}
               </span>

            </template>
          </el-table-column>
          <el-table-column prop="province" align="center" min-width="150">
            <template #header>
              <span>
                  省/市/区
                </span>
            </template>
            <template #default="props">
                <span
                  class="ellipsis">
                  {{props.row.shipping_address && props.row.shipping_address.toString() || '--'}}
               </span>
            </template>
          </el-table-column>
          <el-table-column prop="address" align="center" min-width="200">
            <template #header>

              <span>
                 详细地址
                </span>
            </template>
            <template #default="props">
                <span
                  class="ellipsis">
                  {{props.row.address || '--'}}
               </span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
<!--        <el-card class="box-card">
    <template #header>
      <div class="customerTitle1">
        <span class="leve2_title" style="font-size: 16px;font-weight: 600" >销售信息</span>
      </div>
    </template>
    <div :class="route.query.path == 1 && 'displayForm'">
      <el-form
        label-width="80px"
        :disabled ="route.query.path == 1"
        ref="form_date"
      >
        <el-row :gutter="24">
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" :span="8">
            <el-form-item label="销售员">
             <span>
               {{ groupList && groupList.update_user_name || ''}}
             </span>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" :span="8">
            <el-form-item label="销售部门" class="form_node">
              {{groupList && groupList.sales_dept_name || ''}}
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" :span="8">
            <el-form-item label="销售组">
              {{groupList && groupList.sales_group_name || ''}}
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
    </div>
  </el-card>-->
<!--    <OperatingLog />-->
    <AuditInformation v-if="route.query.path == 1" />
    <OrderLog ref="orderLog" />
    <Address ref="addressSon" />
  </div>
</template>

<script setup lang="ts">
import lodash from "lodash"
import AuditInformation from './AuditInformation.vue'
import ProductsInQuick from './ProductsInQuick.vue'
import Address from './Address.vue'
import {ref} from "vue";
import {ElMessage, ElMessageBox, FormRules} from "element-plus";
import {areaOptions} from "/@/views/corpManagement/corpCustomers/tools";
import router from "/@/router";
import {orderGroupCopy, orderGroupInfo, orderGroupInsert, orderGroupUpdate} from "/@/api/dms/order/group";
import {customer_optionsList} from "/@/api/dms/customer";
import {organization_list} from "/@/api/dms/organization";
import {options_list, optionsCreate} from "/@/api/dms/options";
import OrderLog from './OrderLog.vue'
import OperatingLog from './OperatingLog.vue'
import {filterateContactInformation} from "/@/views/order_management/orderText";
defineOptions({
    name: 'QuickOrder',
  })
// 订单日志   changeLogRef.value._getCustomerPriceLog(id)
const  orderLog = ref<any>(null)
//跳转判断
const orderPath1:any = ref(localStorage.getItem('orderPath1'))
const form_new_date = ref<any>(null)
const route:any = useRoute()
const operating = ref<any>(undefined)
// 获取组
const groupList = ref<any>(undefined)
// 传值产品信息
const copyProductNumber = ref<any>(undefined)
const form_new_list = ref<any>({
  //客户id
  customer_uid:'',
  //销售组织
  sales_org_id:'',
  //运输方式
  transport_type:'',
  //费用结算方式
  payment_type:'',
  //备注
  remark:'',
  sales_user_id:'',
  sales_dept_id:""
})
const rules = ref<FormRules<any>>({
  transport_type: [{ required: true, message: '请选择运输方式', trigger: 'change' }],
  payment_type: [{ required: true, message: '请选择费用结算方式', trigger: 'change' }],
  // sales_group_id: [{ required: true, message: '请选择销售组', trigger: 'change' }],
  sales_dept_id: [{ required: true, message: '请选择销售部门', trigger: 'change' }],
  sales_user_id: [{ required: true, message: '请选择销售员', trigger: 'change' }],
  sales_org_id: [{ required: true, message: '请选择销售组织', trigger: 'change' }],
  customer_uid: [{ required: true, message: '请选择客户', trigger: 'change' }],
})
// **********选择框的内容***********
const customer_list = ref([])
const sales_user_list = ref([{value:'销售员',label:'销售员'}])
const sales_dept_list = ref([{value:'研发部门',label:'研发部门'}])
const sales_org_list = ref([])
const transport_type_list = ref<any>([])
const payment_type_list =ref([{value:'1',label:'运费到付'},{value:'2',label:'运费预付'}])
// 地址
const address_ref =ref<any>(null)
const areaOption = ref<any>([])
const updateValue = ()=>{
  copyProductNumber.value = form_new_list.value || undefined
  products_ref.value.productList = [{id:0,sales_num:0,goods_no:'',price: 0.00,batch_usable_num:0,batch_no:'',expire_date:'',amount:0.00,goods_name:'',barcode:'',spec_name:'',brand_name:'',goods_type:'',sales_unit:'',sales_num:0,order_price:'',including_tax_price:0.00,tax_rate:'',tax:'',total_amount:0.00,warehouse_no:'',warehouse_name:'',stock_org_name:'',settle_org_name:'',remark:'',batch_no_list:[]}]
}
//****** 产品信息**********
const products_ref=ref<any>(null)
const transport = (va:any)=>{
  ElMessageBox.prompt(' ', '添加运输方式', {
    confirmButtonText: '提交',
    cancelButtonText: '取消',
    center: true,
    /*inputPattern:
      /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,*/
    inputErrorMessage: 'Invalid Email',
  })
    .then(({ value }) => {
      optionsCreate({label:value.trim(),level:2,module:'transport_type',module_name:'运输方式',sort:50}).then((data:any)=>{
        if(data.code == 200){
          options_list({module:'transport_type',level:2}).then((data:any)=>{
            if(data.code == 200){
              ElMessage.success(`提交成功`)
              const arr = data.data.map((item:any)=> {return {value:item.uid , label:item.name}})
              transport_type_list.value = [...arr,{value:-1 , label:'自定义',display:true}]
            }
          })
        }
      })
    })
}
// *********按钮***************
const check = ()=>{
  const product_list = products_ref.value.productList
  const  check1 =  product_list.map((item:any,index:any)=>{
    if(item.goods_no == '' || item.goods_no == undefined){
      ElMessage.warning(`序号为 ${index +1}产品编码 不能为空`)
      return false
    }else {
      return true
    }
  })
  const  check2 =  product_list.map((item:any,index:any)=>{
    if(item.goods_name == '' || item.goods_name == undefined){
      ElMessage.warning(`序号为 ${index +1}产品名称 不能为空`)
      return false
    }else {
      return true
    }
  })
  // const  check3 =  product_list.map((item:any,index:any)=>{
  //   if(item.goods_type == '' || item.goods_type == undefined){
  //     ElMessage.warning(`序号为 ${index +1}产品类型 不能为空`)
  //     return false
  //   }else {
  //     return true
  //   }
  // })
  const  check4 =  product_list.map((item:any,index:any)=>{
    if(item.sales_num == '' || item.sales_num == undefined || item.sales_num == 0){
      ElMessage.warning(`序号为 ${index +1}销售数量 不能为0`)
      return false
    }else {
      if( item.batch_usable_num < item.sales_num ){
        ElMessage.warning(`序号为 ${index +1}预计可发量 小于 销售数量`)
        return false
      }else {
        return true
      }

    }
  })
  const  check5 =  product_list.map((item:any,index:any)=>{
    if(item.warehouse_no == '' || item.warehouse_no == undefined){
      ElMessage.warning(`序号为 ${index +1}仓库 不能为空`)
      return false
    }else {
      return true
    }
  })
  // const  check8 =  product_list.map((item:any,index:any)=>{
  //   if(item.tax_rate == '' || item.tax_rate == undefined){
  //     ElMessage.warning(`序号为 ${index +1}税率 不能为空`)
  //     return false
  //   }else {
  //     return true
  //   }
  // })
  const  check9 =  product_list.map((item:any,index:any)=>{
    if(item.sales_unit == '' || item.sales_unit == undefined){
      ElMessage.warning(`序号为 ${index +1}销售单位 不能为空`)
      return false
    }else {
      return true
    }
  })

  const check6 = [...check1,...check2,...check4,...check5,...check9].every(i=>i==true)
  return check6
}
const checkTel = ()=>{
  const product_list = addressList.value
  const  check1 =  product_list.map((item:any,index:any)=>{
    if(item.shipping_contact == '' || item.shipping_contact == undefined){
      ElMessage.warning(`序号为 ${index +1}联系人名称 不能为空`)
      return false
    }else {
      return true
    }
  })
  const  check2 =  product_list.map((item:any,index:any)=>{
    if(item.shipping_tel == '' || item.shipping_tel == undefined){
      ElMessage.warning(`序号为 ${index +1}联系人电话 不能为空`)
      return false
    }else {
      return true
    }
  })
  const  check3 =  product_list.map((item:any,index:any)=>{
    if(item.shipping_address == '' || item.shipping_address == undefined){
      ElMessage.warning(`序号为 ${index +1}省/市/区 不能为空`)
      return false
    }else {
      return true
    }
  })
  const  check8 =  product_list.map((item:any,index:any)=>{
    if(item.address == '' || item.address == undefined){
      ElMessage.warning(`序号为 ${index +1}信息地址 不能为空`)
      return false
    }else {
      return true
    }
  })
  const check6 = [...check1,...check2,...check3,...check8].every(i=>i==true)
  return check6
}
const share_save = lodash.debounce( async (va:any,status:number)=>{
  const product_list = products_ref.value.productList
  const product_many = products_ref.value.products_number?.reduce((obj:any, item:any) => {
    obj[item.item] = item.value;
    return obj;
  }, {})
if(status !== 0){
  const product_check = check()
  const address_check = checkTel()
  if(!product_check){
    document
      .getElementById('financeIds')
      ?.scrollIntoView({ behavior: 'smooth', block: 'center' })
  }else if(!address_check){
    document
      .getElementById('financeId')
      ?.scrollIntoView({ behavior: 'smooth', block: 'center' })
  }
  await va.validate((valid: any, fields: any) => {
    if (valid) {
      if(product_check && address_check) {
        orderGroupUpdate({uid:groupList && groupList.value.uid,status:status,order_info:{...form_new_list.value,...product_many,trade_from:'员工',detail:[...product_list]},location_list:addressList.value?.map((item:any)=>{return{...item,shipping_address:item.shipping_address.toString()}})}).then(()=>{
          if(status == 0){
            ElMessage.success(`暂存成功`)
          }else if(status == 1){
            ElMessage.success(`保存成功`)
          }else if(status == 2){
            ElMessage.success(`提交成功`)
          }
          if(orderPath1.value == 1){
            router.push('/order/sampleOrder')
          }else {
            router.push('/order/orderQuery')
          }

        })
      }
    }
  })
}else {
  orderGroupUpdate({uid:groupList && groupList.value.uid,status:status,order_info:{...form_new_list.value,...product_many,trade_from:'员工',detail:[...product_list]},location_list:addressList.value?.map((item:any)=>{return{...item,shipping_address:item.shipping_address.toString()}})}).then(()=>{
    if(status == 0){
      ElMessage.success(`暂存成功`)
    }else if(status == 1){
      ElMessage.success(`保存成功`)
    }else if(status == 2){
      ElMessage.success(`提交成功`)
    }
    if(orderPath1.value == 1){
      router.push('/order/sampleOrder')
    }else {
      router.push('/order/orderQuery')
    }

  })
}


},500)
// ************地址***********************
const addressList = ref<any>([{id:0,shipping_contact:'',shipping_tel:'',province:'',city:'',county:'',address:''}])
// ********添加地址 删除地址*************
const handleClickAdd =(row:any)=>{
  const newObject = {id:String(new Date().getTime()).slice(-6),shipping_contact:'',shipping_tel:'',province:'',city:'',county:'',address:''}
  const insertIndex = addressList.value.findIndex((item:any)=> item.id === row.id) + 1;
  addressList.value.splice(insertIndex, 0, newObject)
}
const handleClickRemove = (row:any)=>{
  addressList.value =  addressList.value.filter((item:any)=>item.id != row.id)
}
// ******地址簿*******
const addressSon =ref<any>(undefined)
const openAddress = ()=>{
  if(form_new_list.value.customer_uid != '' && form_new_list.value.customer_uid ){
    addressSon.value.dialogVisibles = true
    addressSon.value.customerId = form_new_list.value.customer_uid
    addressSon.value.selectAddress = undefined
  }else {
    ElMessage.warning(`客户不能为空，请先选择客户`)
  }
}
watchEffect(()=>{
  const {selectAddress} =   addressSon.value || []
  if(selectAddress && selectAddress.length > 0){
    const arr = selectAddress.map((i:any,index:any)=>{return {...i,id:String(new Date().getTime()).slice(-6)+index}})
    addressList.value = [...filterateContactInformation(addressList.value),...arr]
    addressSon.value.selectAddress = []
  }
  copyProductNumber.value = form_new_list.value || undefined
})
// 单选
const radioIndex = ref(null)
const handleRadio = (row: any) => {
  radioIndex.value = row.id
}//获取客户
const getCustomer=async ()=>{
  // 客户
  await customer_optionsList({is_group:2,name:''}).then((data:any)=>{
    if(data.code == 200){
      customer_list.value = data.data.map((item:any)=> {return {value:item.uid , label:item.name}})
    }
  })
  // 组织
  await  organization_list({}).then((data:any)=>{
    if(data.code == 200){
      sales_org_list.value = data.data.map((item:any)=> {return {value:item.uid , label:item.name}})
    }
  })
  // 运输方式
  await options_list({module:'transport_type',level:2}).then((data:any)=>{
    if(data.code == 200){
      const arr = data.data.map((item:any)=> {return {value:item.uid , label:item.name}})
      transport_type_list.value = [...arr,{value:-1 , label:'自定义',display:true}]
    }
  })
  //地址
  areaOption.value = await areaOptions()
}

const back = ()=>{
  if(orderPath1.value == 1){
    router.push('/order/sampleOrder')
  }else {
    router.push('/order/orderQuery')
  }
}
const orderGroup = ()=>{
  if(route.query.id){
    if(route.query.path == 3){
      //样品订单复制
      orderGroupCopy({uid:route.query.id}).then((data:any)=>{
        if(data.code == 200){
          groupList.value = data.data
          form_new_list.value = {
            //客户id
            customer_uid:data.data.order_info.customer_uid,
            //销售组织
            sales_org_id:data.data.order_info.sales_org_id,
            //运输方式
            transport_type:data.data.order_info.transport_type,
            //费用结算方式
            payment_type:data.data.order_info.payment_type,
            //备注
            remark:data.data.order_info.remark,
            sales_user_id:data.data.sales_user_name,
            sales_dept_id:data.data.sales_dept_name

          }
          addressList.value=  data.data.location_list.length>0 && data.data.location_list.map((item:any)=> {return{...item,shipping_address:item.shipping_address.split(",")}}) || [{id:0,shipping_contact:'',shipping_tel:'',province:'',city:'',county:'',address:''}]
          products_ref.value.productList = data.data.order_info.detail
          copyProductNumber.value = data.data.order_info || undefined
        }
      })
    }else {
      orderGroupInfo({uid:route.query.id}).then((data:any)=>{
        if(data.code == 200){
          groupList.value = data.data
          orderLog.value._getCustomerPriceLog(route.query.id)
          form_new_list.value = {
            //客户id
            customer_uid:data.data.order_info.customer_uid,
            //销售组织
            sales_org_id:data.data.order_info.sales_org_id,
            //运输方式
            transport_type:data.data.order_info.transport_type,
            //费用结算方式
            payment_type:data.data.order_info.payment_type,
            //备注
            remark:data.data.order_info.remark,
            sales_user_id:data.data.sales_user_name,
            sales_dept_id:data.data.sales_dept_name
          }
          addressList.value=  data.data.location_list.length>0 &&  data.data.location_list.map((item:any)=> {return{...item,shipping_address:item.shipping_address.split(",")}}) || [{id:0,shipping_contact:'',shipping_tel:'',province:'',city:'',county:'',address:''}]
          products_ref.value.productList = data.data.order_info && data.data.order_info.detail.length >0  && data.data.order_info.detail || [{id:0,sales_num:0,goods_no:'',price: 0.00,batch_usable_num:0,batch_no:'',expire_date:'',amount:0.00,goods_name:'',barcode:'',spec_name:'',brand_name:'',goods_type:'',sales_unit:'',sales_num:0,order_price:'',including_tax_price:0.00,tax_rate:'',tax:'',total_amount:0.00,warehouse_no:'',warehouse_name:'',stock_org_name:'',settle_org_name:'',remark:'',batch_no_list:[]}]
          copyProductNumber.value =  data.data.order_info && data.data.order_info || undefined
        }
      })
    }
  }else {
    //获取组id
    orderGroupInsert({type:3}).then((data:any)=>{
      if(data.code == 200){
        groupList.value = data.data
        orderLog.value._getCustomerPriceLog(data.data.uid)
        form_new_list.value = {
        ...form_new_list.value,
          sales_user_id:data.data.sales_user_name,
          sales_dept_id:data.data.sales_dept_name
        }
      }
    })
  }
}
onMounted(async ()=>{
  getCustomer()
  orderGroup()
  // 获取地址
  /*areaOption.value = await areaOptions()
  orderGroupInsert({type:3}).then((data:any)=>{
    if(data.code == 200){
      groupList.value = data.data
    }
  })*/
})

</script>

<style lang="scss" scoped>
@import "../index";

</style>

